	var iswxpay = 0;
	var openid = '0';
	$(function() {
		if(iswx==1){
			var index = ua.indexOf('micromessenger');
			var wxversion = parseFloat(ua.slice(index+15));
			if(wxversion>=5){
				iswxpay = 1;
				$('#pay_wx').removeClass('none');
				$('#pay_zfb>.zf_title').html('会遇到支付拦截，推荐使用微信支付');
				$('#pay_wx_wap').addClass('none');
			}
		}
		var flags = 1;
		var orderresult = null;
		var durations = 15;
		if(flags==1){
			orderresult = {"totalPrice":239,"order_id_list":"MTIyMDA3NDMwMjQzOTE4NDQ1","orderInfo":null,"successType":1,"express":{"area_name":"静安区","invoice_title":"","send_type":0,"area_id":"310106","create_by":"2627276","expresstype_id":2,"city_name":"市辖区","express_code":"","update_time":"2016-09-19 16:27:19","mobile_phone":"15221744121","invoice_type":0,"update_by":"2627276","address":"111","create_time":"2016-09-19 16:27:19.213","receiver":"111","confirm_receive_time":"","hasDelay":0,"production_time":"","need_invoice":0,"province_name":"上海市","express_comment":"","express_id":0,"send_time":"","phone":"15221744121","province_id":"310000","post_code":"","expressTypeCode":"","order_id":122007430243918445,"supplier_id":130036,"city_id":"310100"},"hasPresale":false};
			if(orderresult.orderInfo&&orderresult.orderInfo!=null){
				$('#pay_cft,#pay_wx,#pay_cfta,#pay_cftb').remove();
				$('#pay_zfb').after('<div class="pay_zf ofh" id="pay_cftb"><span class="xyk_pic f_l">拉卡拉</span><span class="zf_title">使用拉卡拉支付</span></div>');
			}
			if(orderresult.successType == 2){
				OurBox.alert('该订单已付款',function(){},{width:'120'});
				setTimeout(function(){
					window.location.href="/cart/list.html";
				},2000);
				return false;
			}
		}else if(flags==2){
			OurBox.alert('该订单已付款',function(){},{width:'120'});
			setTimeout(function(){
				window.location.href="/cart/list.html";
			},2000);
			return false;
		}else if(flags==0){
			OurBox.alert('该订单已经取消',function(){window.location.href='/order/orderlist';},{width:'120'});
			setTimeout(function(){
				window.location.href="/cart/list.html";
			},2000);
			return false
		}else{
			OurBox.alert('该订单有异常，请重新下单试试',function(){window.location.href='/order/orderlist';},{width:'200'});
			setTimeout(function(){
				window.location.href="/cart/list.html";
			},2000);
			return false;
		}
		
		if(iswxpay == 1){
			$.ajax({
				url:'/getwxsign',
				dataType:'json',
				type:'GET',
				data:{url:encodeURIComponent(window.location.href)},
				success:function(data){
					 if (data.success == 1) {
						 wx.config({
							    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
							    appId: data.data.wxconfig.appid, // 必填，公众号的唯一标识
							    timestamp: data.data.wxconfig.timestamp, // 必填，生成签名的时间戳
							    nonceStr: data.data.wxconfig.nonceStr, // 必填，生成签名的随机串
							    signature: data.data.wxconfig.signature,// 必填，签名，见附录1
							    jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
							});
					 }
				},
				error:function(){
					
				}
			})
		}
		
		var ismilife = 0;
		var userinfo = getCookie("userinfo");
		if(userinfo.split(',').length>4&&userinfo.split(',')[4]==7){
			ismilife = 1; 
		}
		//财付通
		$('#pay_cft,#pay_cfta,#pay_cftb').click(function(){
			$(this).css('background-color','#f5f5f5');
			$(this).find('.zf_title').css('color','#cccccc');
			$('body').ourLoading({'iscmask':1});
			setTimeout(function(){
				var paycookie= orderresult.totalPrice +','+$('#duration').html()+','+$('#address').html();
				setCookie("paycookie",encodeURI(paycookie),'1','/');
				$.ajax({
					url:"/order/gettotenid",
					type:"post",
					dataType:"json",
					data:{order_id_list:orderresult.order_id_list,paytype:1},
					async:false,
					contentType:"application/x-www-form-urlencoded;charset=utf-8",
					success:function(data){
						if(data.success==1){
							$('body').ourUnLoading();
							$('#pay_cft').css('background-color','#ffffff');
							$('#pay_cft').find('.zf_title').css('color','#999999');
							var extent = 'payCode,'+orderresult.order_id_list+'|token,'+ data.data.token_id;
							window.location.href="https://www.tenpay.com/app/mpay/mp_gate.cgi?token_id="+ data.data.token_id;							
						}else if(data.error.code==212003){
							$('body').ourUnLoading();
							$('#pay_cft').css('background-color','#ffffff');
							$('#pay_cft').find('.zf_title').css('color','#999999');
							OurBox.alert('该订单已取消',function(){window.location.href='/order/orderlist';},{width:'200'});
						}else{
							$('body').ourUnLoading();
							$('#pay_cft').css('background-color','#ffffff');
							$('#pay_cft').find('.zf_title').css('color','#999999');
							OurBox.alert('获取支付信息失败，请稍后重试',function(){
							},{width:'200'});
						}
					},
					error:function(data){
						$('body').ourUnLoading();
						$('#pay_cft').css('background-color','#ffffff');
						$('#pay_cft').find('.zf_title').css('color','#999999');
						OurBox.alert('网络连接失败，请稍后重试',function(){},{width:'170'});
					}
				})
			},100);
		});
		//支付宝		
		$('#pay_zfb').click(function(){
			$(this).css('background-color','#f5f5f5');
			$(this).find('.zf_title').css('color','#cccccc');
			$('body').ourLoading({'iscmask':1});
			setTimeout(function(){
				var paycookie= orderresult.totalPrice +','+$('#duration').html()+','+$('#address').html();
				setCookie("paycookie",encodeURI(paycookie),'1','/');
				$.ajax({
					url:"/order/gettotenid",
					type:"post",
					dataType:"json",
					data:{order_id_list:orderresult.order_id_list,paytype:3,ismilife:ismilife},
					async:false,
					contentType:"application/x-www-form-urlencoded;charset=utf-8",
					success:function(data){
						$('body').ourUnLoading();
						$('#pay_zfb').css('background-color','#ffffff');	
						$('#pay_zfb').find('.zf_title').css('color','#999999');	
						if(data.success==1){	
							var extent = 'payCode,'+orderresult.order_id_list+'|param,'+ data.data.param;
							if(ismilife==0){
								window.location.href="https://wappaygw.alipay.com/service/rest.htm?"+ data.data.param;
							}else{
 								window.myjs.setSuccessUrl("https://m.biyao.com/order/paysucceed");
 								window.myjs.callPayment("alipay",data.data.orderStr);
							}
						}else if(data.error.code==212003){
							OurBox.alert('该订单已取消',function(){window.location.href='/order/orderlist';
							},{width:'200'});
						}else{
							OurBox.alert('获取支付信息失败，请稍后重试',function(){
							},{width:'200'});
						}
					},
					error:function(data){
						$('body').ourUnLoading();
						$('#pay_zfb').css('background-color','#ffffff');	
						$('#pay_zfb').find('.zf_title').css('color','#999999');	
						OurBox.alert('网络连接失败，请稍后重试',function(){},{width:'170'});
					}
				})
			},100);
		});
		
		$('#pay_wx').click(function(){
			$(this).css('background-color','#f5f5f5');
			$(this).find('.zf_title').css('color','#cccccc');
			$('body').ourLoading({'iscmask':1});
			var paycookie= orderresult.totalPrice +','+$('#duration').html()+','+$('#address').html();
			setCookie("paycookie",encodeURI(paycookie),'1','/');
			if(openid==0){
				OurBox.confirm("微信认证失败,请在订单重新支付",function(){window.location.href=window.ControllerSite+"/orderSU/orderlist"});
				return false;
			}
			setTimeout(function(){		
				$.ajax({
					url:"/order/gettotenid",
					type:"post",
					dataType:"json",
					data:{order_id_list:orderresult.order_id_list,paytype:5,openid:openid},
					async:false,
					contentType:"application/x-www-form-urlencoded;charset=utf-8",
					success:function(data){
						$('body').ourUnLoading();		
						$('#pay_wx').css('background-color','#ffffff');	
						$('#pay_wx').find('.zf_title').css('color','#999999');	
						if(data.success==1){
							setTimeout(function(){							
								wx.chooseWXPay({
								    timestamp: data.data.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
								    nonceStr: data.data.nonce_str, // 支付签名随机串，不长于 32 位
								    package: 'prepay_id='+data.data.prepay_id, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
								    signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
								    paySign: data.data.sign, // 支付签名
								    success: function (res) {
								        // 支付成功后的回调函数
								        setTimeout(function(){
								    		window.location.href='/order/paysucceed';
								    	},1000);
								    },
								    fail:function(res){
								    	//记录微信支付错误站日志
								    	MBase.m.log(JSON.stringify(data)+'wxpayerror=='+JSON.stringify(res)+openid);
								    	//给出友好提示
								    	OurBox.alert('请选择其他支付方式或在其它浏览器中重新打开页面进行支付',function(){},{stay:'120000'});
							    	}
								});
							},100);	
							
						}else if(data.error.code==212003){
							OurBox.alert('该订单已取消',function(){window.location.href='/order/orderlist'},{width:'200'});
						}else{
							OurBox.alert('获取支付信息失败，请稍后重试',function(){},{width:'200'});
						}
					},
					error:function(data){
						$('body').ourUnLoading();		
						$('#pay_wx').css('background-color','#ffffff');	
						$('#pay_wx').find('.zf_title').css('color','#999999');	
						OurBox.alert('网络连接失败，请稍后重试',function(){},{width:'170'});
					}
				})
			},100);	
		});
		
		$('#pay_wx_wap').click(function(){
			$(this).css('background-color','#f5f5f5');
			$(this).find('.zf_title').css('color','#cccccc');
			$('body').ourLoading({'iscmask':1});
			var paycookie= orderresult.totalPrice +','+$('#duration').html()+','+$('#address').html();
			setCookie("paycookie",encodeURI(paycookie),'1','/');

			setTimeout(function(){		
				$.ajax({
					url:"/order/gettotenid",
					type:"post",
					dataType:"json",
					data:{order_id_list:orderresult.order_id_list,paytype:6},
					async:false,
					contentType:"application/x-www-form-urlencoded;charset=utf-8",
					success:function(data){
						$('body').ourUnLoading();		
						$('#pay_wx').css('background-color','#ffffff');	
						$('#pay_wx').find('.zf_title').css('color','#999999');
						if(data.success==1){
							setTimeout(function(){							
								var str1= "appid="+encodeURIComponent(data.data.appid)+"&noncestr="+encodeURIComponent(data.data.nonce_str)
								+ "&package=WAP&prepayid="+encodeURIComponent(data.data.prepay_id)+"&sign="+encodeURIComponent(data.data.sign)
								+"&timestamp="+encodeURIComponent(data.data.timeStamp);
								window.location="weixin://wap/pay?"+encodeURIComponent(str1);
								
							},100);	
							setTimeout(function(){
								OurBox.spconfirm("<div style='font-size: 15px;font-weight: bold;'>支付确认</div><div style='text-align: left;margin-top: 5px;'>1.请在微信内完成微信支付，如果已支付成功，请点击已完成；</div> <div style='text-align: left;margin-top: 10px;margin-bottom: 5px;'>2.如果未安装微信6.0.2以上版本客户端，请点击未支付并选择其他支付方式；</div>"
										,"已完成","未支付",function(){window.location.href='/order/paysucceed';},function(){},{});
							},5000);	
						}else if(data.error.code==212003){
							
							OurBox.alert('该订单已取消',function(){window.location.href='/order/orderlist';
							},{width:'200'});
						}else{
							
							OurBox.alert('获取支付信息失败，请稍后重试',function(){
							},{width:'200'});
						}
					},
					error:function(data){
						$('body').ourUnLoading();		
						$('#pay_wx').css('background-color','#ffffff');	
						$('#pay_wx').find('.zf_title').css('color','#999999');	
						OurBox.alert('网络连接失败，请稍后重试',function(){},{width:'170'});
					}
				})
			},100);	
		});
		
		
		$('#dd_price').html('￥'+orderresult.totalPrice.toFixed(0));
		$('#totalprice').val(orderresult.totalPrice.toFixed(0));
		$('#address').html(orderresult.express.receiver+'   ' +orderresult.express.mobile_phone+'   '+orderresult.express.province_name+((orderresult.express.city_name=="市辖区"||orderresult.express.city_name=="县")?"":orderresult.express.city_name)+orderresult.express.area_name+orderresult.express.address);
		$('#duration').html(durations+'天');
		$('#order_id_list').val(orderresult.order_id_list);
		//$('#orderpaycode').val(orderresult.mergeOrderId)
		if(orderresult.hasPresale==true){
			$('.pay_zs').html('您购买的商品参加下单分享免邮活动，现在分享，立刻免邮！');
		}else{
			$('.pay_zs').html('预售订单需按正价支付，预售结束后根据购买人数计算折扣，如有差价，将在5个工作日返还到您的支付账号。');
		}
		//加载点击效果
		MBase.active.addactive();
		MBase.active.addotheract($('.pay_zf'));
	})

	wx.ready(function(){
	//alert("ready");
	/*
	 * 判断当前客户端版本是否支持指定JS接口
	 */
		wx.checkJsApi({
	    	jsApiList: ['chooseWXPay'],// 需要检测的JS接口列表，所有JS接口列表见附录2,
	    	success: function(res) {
	        // 以键值对的形式返回，可用的api值true，不可用为false
	        // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
	    	}
		});
	
		
	});
	
	function showErrorBar(errorInfo){
		OurBox.alert(errorInfo);
	}